package com.zhangqiancheng.wcdmaconsole;

import java.io.IOException;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.ProtocalAndUdp.ReadWriteFile;
import com.ProtocalAndUdp.UdpClientSocket;
import com.ProtocalAndUdp.Util;
import com.ProtocalAndUdp.XlsOperate;

public class MainActivity extends ConsoleActivityBase {

	private Handler handler;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		// 初始化日志
		ReadWriteFile.setFileName("Log" + Util.getNowLongTime() + ".txt");
		try {
			ReadWriteFile.writeTxtFile(this, "软件开启");
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId() == R.id.action_exit)
			finish();

		return super.onOptionsItemSelected(item);
	}

	public void dataButtonClick(View view) {
		startActivity(new Intent(this, DataActivity.class));
	}

	public void sysButtonClick(View view) {
		startActivity(new Intent(this, SysSettingActivity.class));
	}

	public void aboutButtonClick(View view) {

		AlertDialog.Builder builder = new Builder(MainActivity.this);
		builder.setIcon(android.R.drawable.btn_star);
		builder.setMessage("操控台 v1.0 测试版\n\nCopyright 2013 All rights reserved.");
		builder.setTitle("关于");
		builder.setPositiveButton("确定", new OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {

				dialog.dismiss();
			}
		});
		builder.create().show();
	}

	@Override
	protected void onDestroy() {
		try {
			UdpClientSocket.getClient().isRun = false;
			UdpClientSocket.getClient().Close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		super.onDestroy();
	}

	public void onOpenClick(View view) {

	}
}
